﻿Imports Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Imports System.Management

Public Class GetDomains
    Public Shared Function Getdoms() As List(Of String)
        Dim connection As WqlConnectionManager
        connection = ConnectSmsProvider.Connect()
        Dim doms = New List(Of String)
        Dim domres = New List(Of String)
        Dim objrsys = connection.QueryProcessor.ExecuteQuery("select distinct LastLogonUserDomain from SMS_R_System")
        For Each res In objrsys
            If Not doms.Contains(res.properties("LastLogonUserDomain").stringvalue()) Then
                doms.Add(res.properties("LastLogonUserDomain").stringvalue())
            End If
        Next
        Dim query As ManagementObjectSearcher
        query = New ManagementObjectSearcher("Select * from Win32_NetworkAdapterConfiguration")
        For Each oReturn In query.Get
            Try
                'If oReturn("DNSDomainSuffixSearchOrder").count > 0 Then
                For Each dnssuf In oReturn("DNSDomainSuffixSearchOrder")
                    Dim dnssufs = Split(dnssuf, ".")
                    If doms.Contains(UCase(dnssufs(0))) Then
                        If Not domres.Contains(UCase(dnssufs(0))) Then
                            domres.Add(UCase(dnssufs(0)))
                        End If
                    End If
                Next
                'End If
            Catch

            End Try
        Next
        Return domres
    End Function
End Class
